# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=mercurial
pkgver=6.2
pkgrel=0
pkgdesc="Scalable distributed SCM tool"
url="https://www.mercurial-scm.org/"
arch="all"
license="GPL-2.0-or-later"
depends="python3"
makedepends="python3-dev"
checkdepends="bash unzip diffutils xz sqlite gettext py3-docutils"
subpackages="
	$pkgname-doc
	$pkgname-vim:vim:noarch
	$pkgname-zsh-completion
	$pkgname-bash-completion
	"
source="https://www.mercurial-scm.org/release/mercurial-$pkgver.tar.gz
	blacklist.txt
	"
case "$CARCH" in
	aarch64|armhf) options="$options !check" ;;  # around 400 of 919 tests time out
esac
case "$CARCH" in
	# Oxidation, limited by Rust
	x86_64|armv7|armhf|aarch64|x86|ppc64le) makedepends="$makedepends cargo" ;;
esac

# secfixes:
#   4.9-r0:
#     - CVE-2019-3902

build() {
	HGPYTHON3=1 python3 setup.py build
}

check() {
	make PYTHON=python3 TESTFLAGS=--blacklist="$srcdir/blacklist.txt" tests
}

package() {
	HGPYTHON3=1 python3 setup.py install --root="$pkgdir"
	install -m755 contrib/hgk contrib/hg-ssh hgeditor "$pkgdir"/usr/bin

	local man
	for man in doc/*.?; do
		install -Dm644 "$man" \
			"$pkgdir"/usr/share/man/man${man##*.}/${man##*/}
	done
}

vim() {
	depends=""
	pkgdesc="Vim syntax for $pkgname"
	install_if="vim $pkgname=$pkgver-r$pkgrel"

	cd "$builddir"/contrib/vim/
	mkdir -p "$subpkgdir"/usr/share/vim/vimfiles/syntax/
	install -Dm644 HGAnnotate.vim hgtest.vim \
		"$subpkgdir"/usr/share/vim/vimfiles/syntax/
}

sha512sums="
0c988a558e60ba456196420dcf720558f6ce63fcc42bf43a8f6af16289b5f2a81738a4c038a620040394215e3e57ba254ee56fa072962f7bd0b3b191d8334fef  mercurial-6.2.tar.gz
b24e1b79ca36ac1d78a5af4e35eb87581f209255838327a7d9315c17175d41bfa4b7f98c66be078cfa1e7d27a41c1a12bba265fa6d3d30edb4e2ba599fe0ed18  blacklist.txt
"
